package com.hexiang.deathlock;

import java.util.concurrent.TimeUnit;

/**
 *
 */
public class ThreadDeathLock {

	public static void main(String[] args) {
		final Object left = new Object();
		final Object right = new Object();

		Thread leftThread = new Thread(() -> {

			synchronized (left) {
				try {
					TimeUnit.MILLISECONDS.sleep(200);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (right) {
					try {
						TimeUnit.MILLISECONDS.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});

		Thread rightThread = new Thread(() -> {
			synchronized (right) {
				try {
					TimeUnit.MILLISECONDS.sleep(200);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (left) {
					try {
						TimeUnit.MILLISECONDS.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});

		leftThread.start();
		rightThread.start();
	}
}
